----------------------------------------------------------------------------------------------------------------------------------
--[[

    蝶引来生 （Butterfly's Embrace）

]]--
----------------------------------------------------------------------------------------------------------------------------------
---
    local function GetReplica(self)
        return self.inst.replica.hutao_com_butterfly_s_embrace or self.inst.replica._.hutao_com_butterfly_s_embrace
    end
    local function set_debuff(self, debuff)
        local replica = GetReplica(self)
        if replica then
            replica:SetDebuff(debuff)
        end
    end
    local function set_health_cost(self, health_cost)
        local replica = GetReplica(self)
        if replica then
            replica:SetHealthCost(health_cost)
        end
    end
    local function set_debuff_remain_time(self, debuff_remain_time)
        local replica = GetReplica(self)
        if replica then
            replica:SetDebuffRemainTime(debuff_remain_time)
        end
    end
    local function set_debuff_active_time(self, debuff_active_time)
        local replica = GetReplica(self)
        if replica then
            replica:SetDebuffActiveTime(debuff_active_time)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------
local hutao_com_butterfly_s_embrace = Class(function(self, inst)
    self.inst = inst

    self.debuff = nil

    self.health_cost = 0

    self.debuff_remain_time = 0
    self.debuff_active_time = 0

    self.inst:ListenForEvent("death",function()
        self:Stop()
    end)

end,
nil,
{
    debuff = set_debuff,
    health_cost = set_health_cost,
    debuff_remain_time = set_debuff_remain_time,
    debuff_active_time = set_debuff_active_time,
})

------------------------------------------------------------------------------------------------------------------------------
---
    function hutao_com_butterfly_s_embrace:SetStartFn(start_fn)
        self.start_fn = start_fn
    end
------------------------------------------------------------------------------------------------------------------------------
---
    local debuff_prefab = "hutao_debuff_phantom_butterfly_dance"
    function hutao_com_butterfly_s_embrace:Start(health_cost)
        if self:IsActiving() then
            return
        end
        local test_num = 100
        local debuff_inst = nil
        while test_num > 0 do
            debuff_inst = self.inst:GetDebuff(debuff_prefab)
            if debuff_inst and debuff_inst:IsValid() then
                break
            end
            self.inst:AddDebuff(debuff_prefab,debuff_prefab)
            test_num = test_num - 1
        end
        if debuff_inst and debuff_inst:IsValid() then
            self.debuff = debuff_inst
            self.health_cost = health_cost
            if self.start_fn then
                self.start_fn(self.inst)
            end
        end
    end
    function hutao_com_butterfly_s_embrace:Stop()
        if self.debuff and self.debuff:IsValid() then
            self.debuff:Remove()
            self.debuff = nil
        end
        self.health_cost = 0
        self.debuff_remain_time = 0
        self.debuff_active_time = 0
    end
    function hutao_com_butterfly_s_embrace:IsActiving()
        if self.debuff and self.debuff:IsValid() then
            return true
        end
        return false
    end
    function hutao_com_butterfly_s_embrace:GetHealthCost()
        return self.health_cost
    end
------------------------------------------------------------------------------------------------------------------------------
---
    function hutao_com_butterfly_s_embrace:SetDebuffRemainTime(debuff_remain_time)
        self.debuff_remain_time = debuff_remain_time
    end
    function hutao_com_butterfly_s_embrace:GetDebuffRemainTime()
        return self.debuff_remain_time
    end
    function hutao_com_butterfly_s_embrace:RemainTimeDoDelta(value)
        self.debuff_remain_time = math.clamp(self.debuff_remain_time + value,0,1000000)
        return self.debuff_remain_time
    end

    function hutao_com_butterfly_s_embrace:ActiveTimeDoDelta(value)
        self.debuff_active_time = math.clamp(self.debuff_active_time + value,0,1000000)
        return self.debuff_active_time
    end
------------------------------------------------------------------------------------------------------------------------------
return hutao_com_butterfly_s_embrace







